#include "application.h"
#include "state.h"
#include "state_stack.h"
#include "input.h"
#include "debug_helper.h"
#include "tag.h"
#include "timer.h"

#include <iostream>
#include <exception>

using namespace krryn::core;
using namespace krryn::system;

application::application() : m_Stack(state_stack::get_instance()){
}

application::~application(){
    while(!m_Stack.empty()){
		m_Stack.pop();
	}
}

void application::run(){
	redirect_io(redirect_error);
	
	std::clog << "Hello!" << std::endl;    
	m_Stack.push(":intro");

	timer l_Timer;
	float l_DeltaTime = 0;
    
    while(!m_Stack.empty()){
		l_Timer.begin();

		m_Stack.current().tick(l_DeltaTime);

		l_DeltaTime = l_Timer.duration_in_seconds();
		l_Timer.end();
	}

	std::clog << "Bye, bye!" << std::endl;
}
